//找单身狗，两个数字
#include<stdio.h>
int main()
{
	int size, i, num, count, dog1, dog2;
	int arr[] = { 1,2,1,3,2,5,4,5,9,8,9,8,3,45 };
	num = arr[0];
	count = 0;//记录位数
	size = sizeof(arr) / sizeof(arr[0]);
	//数组的所有元素进行异或，结果为两个单身狗异或之和
	for (i = 1; i < size; i++)
		num ^= arr[i];
	
	//找出异或后的第几位二进制为1，两个单身狗该对应位相异。
	while (!(num & 1)) {
		num >>= 1;;
		count++;
	}

	//将第count位为1的二进制进行异或，其结果为一个单身狗
	dog1 = 0;
	for (i = 0; i < size; i++) {
		if (((arr[i] >> count) & 1) == 1)
			dog1 ^= arr[i];
	}

	//所得dog1即为一个单身狗，将num异或dog1,所得即为dog2
	dog2 = num ^ dog1;
	printf("dog1=%d  dog2=%d\n", dog1, dog2);
		return 0;
}